<?php

namespace app\admin\controller;

use think\Lang;

/**
 *服务人员实名认证
 */
class Fupersonalshiming extends AdminControl
{

    public function _initialize()
    {
        parent::_initialize();
        Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/fupersonal.lang.php');
    }

    /**
     * 列表
     * @return mixed
     */
    public function index()
    {
        $model = model('fupersonal');
        $condition = [];
        $condition['cardstatus'] = 3; #提交信息,等待认证的
        /**
         * 检索条件
         */
        if (!empty(trim(input('search_phone')))) {
            $condition['phone'] = array('like', '%' . trim(input('search_phone')) . '%');
        }
        if (!empty(trim(input('search_name')))) {
            $condition['ds_fuwu_personal.name'] = array('like', '%' . trim(input('search_name')) . '%');
        }
        $data = $model->getList($condition, 'ds_fuwu_personal.*,s.name as skillname,g.name as gradename', 10);
        $this->assign('data', $data);
        $this->assign('status', $condition['cardstatus']);
        $this->assign('showpage', $model->page_info->render());
        $this->assign('search_phone', trim(input('search_phone')));
        $this->assign('search_name', trim(input('search_name')));
        $this->setAdminCurItem('index');
        return $this->fetch();
    }

    /**
     * 成功
     * @return mixed
     */
    public function chenggong()
    {
        $model = model('fupersonal');
        $condition = [];
        $condition['cardstatus'] = 1; #提交信息,认证成功的
        /**
         * 检索条件
         */
        if (!empty(trim(input('search_phone')))) {
            $condition['phone'] = array('like', '%' . trim(input('search_phone')) . '%');
        }
        if (!empty(trim(input('search_name')))) {
            $condition['ds_fuwu_personal.name'] = array('like', '%' . trim(input('search_name')) . '%');
        }
        $data = $model->getList($condition, 'ds_fuwu_personal.*,s.name as skillname,g.name as gradename', 10);
        $this->assign('data', $data);
        $this->assign('status', $condition['cardstatus']);
        $this->assign('showpage', $model->page_info->render());
        $this->assign('search_phone', trim(input('search_phone')));
        $this->assign('search_name', trim(input('search_name')));
        $this->setAdminCurItem('chenggong');
        //        $this->assign('cardstatus',1);
        return $this->fetch('index');
    }
    /**
     * 失败
     */
    public function shibai()
    {
        $model = model('fupersonal');
        $condition = [];
        $condition['cardstatus'] = 2; #提交信息,认证成功的
        /**
         * 检索条件
         */
        if (!empty(trim(input('search_phone')))) {
            $condition['phone'] = array('like', '%' . trim(input('search_phone')) . '%');
        }
        if (!empty(trim(input('search_name')))) {
            $condition['ds_fuwu_personal.name'] = array('like', '%' . trim(input('search_name')) . '%');
        }
        $data = $model->getList($condition, 'ds_fuwu_personal.*,s.name as skillname,g.name as gradename', 10);
        $this->assign('data', $data);
        $this->assign('status', $condition['cardstatus']);
        $this->assign('showpage', $model->page_info->render());
        $this->assign('search_phone', trim(input('search_phone')));
        $this->assign('search_name', trim(input('search_name')));
        $this->setAdminCurItem('shibai');
        //        $this->assign('cardstatus',1);
        return $this->fetch('index');
    }

    /**
     * 查看详情
     */
    public function view()
    {
        $model = model('fupersonal');
        if (request()->isPost()) {
            $fuwu_info = $model->info(['id' => input('id')]); 

            $data['cardstatus'] = input('cardstatus');

            #认证通过之后，根据身份证号判断性别 出生日期
            if($data['cardstatus'] ==  1){
                $data['sex']  = getSex($fuwu_info['idcard']);
                $result = getIDCardInfo($fuwu_info['idcard']);
                $data['birthday'] = $result['birthday'];
            }
            $data['cardfail_resonse'] = input('cardfail_resonse');
            $data['status_admin_id'] = session('admin_id');
            $data['status_admin_name'] = session('admin_name');
            $data['status_at'] = date('Y-m-d H:i:s', time());

            #通知内容
            $notif_data = [
                'order_id' =>  '',
                'notif_title' => '认证通知',
                'notif_content' =>  '您提交的实名认证已审核，请及时查看',
                'member_id' => $fuwu_info['id'],
                'member_name' => $fuwu_info['name'],
            ];
            model('points')->saveAfficeslog(2, 1, $notif_data); #服务
            pushMessageToSingle('追加工时通知', $fuwu_info['clientid'], '您提交的实名认证已审核，请及时查看');

            if ($res = $model->edit(['id' => $_POST['id']], $data)) {
                $this->log(lang('ds_update') . lang('fuwu_personal_D') . '[' . input('post.name') . ']', 1);
                dsLayerOpenSuccess(lang('ds_common_save_succ'));
            } else {
                $this->log(lang('ds_update') . lang('fuwu_personal_D') . '[' . input('post.name') . ']', 0);
                $this->error(lang('ds_common_save_fail'));
            }
        } else {
            $data = $model->info(['id' => input('id')]);
            $this->setAdminCurItem('view');
            $this->assign('data', $data);
            $this->assign('id', input('id'));
            return $this->fetch();
        }
    }

    public function datu()
    {
        $data  = input('img');
        if ($data) {
            if ((strpos($data, 'https://') === false) && (strpos($data, 'http://') === false)) {
                return '图片格式不正确';
            }
            $statsu = input('status') ? input('status') : 0;
            if ($statsu) {
                return '<div  align="center"><img src="' . $data . '" height="350px;" /></div>';
            }
            return '<div  align="center"><img src="' . $data . '" height="440px;" /></div>';
        } else {
            return '未上传';
        }
    }


    /**
     * 获取卖家栏目列表,针对控制器下的栏目
     */
    protected function getAdminItemList()
    {
        $menu_array = array(
            array(
                'name' => 'index',
                'text' => '待审核',
                'url' => url('Fupersonalshiming/index'),
            ),
            array(
                'name' => 'chenggong',
                'text' => '审核成功',
                'url' => url('Fupersonalshiming/chenggong'),
            ),
            array(
                'name' => 'shibai',
                'text' => '审核失败',
                'url' => url('Fupersonalshiming/shibai'),
            ),

        );
        if (request()->action() == 'view') {
            $menu_array[] = array(
                'name' => 'view',
                'text' => '查看审核',
                'url' => 'javascript:void(0)'
            );
        }
        return $menu_array;
    }
}
